package com.aidenj.service;

import com.aidenj.mapper.ChannelInfoMapper;
import com.aidenj.model.ChannelInfo;
import com.github.pagehelper.ISelect;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service(value = "channelInfoService")
public class ChannelInfoServiceImpl implements ChannelInfoService {

    @Resource
    private ChannelInfoMapper channelInfoMapper;

    @Override
    public ChannelInfo selectByPrimaryKey(ChannelInfo channelInfo) {
        System.out.println("传递参数："+channelInfo.toString());

        channelInfo = channelInfoMapper.selectByPrimaryKey(channelInfo);
        System.out.println("查询结果："+channelInfo.toString());
        return channelInfo;
    }

    @Override
    public List<ChannelInfo> fandPageChannelInfo(ChannelInfo channelInfo, Integer pageNum,Integer pageSize) {
        //int pageSize = channelInfoMapper.findChannelInfoCount(channelInfo);
        //page.setPageSize(pageSize);

//        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        Page<ChannelInfo> p = PageHelper.startPage(pageNum,pageSize,true);
        System.out.println(p);

        //PageHelper.
        List<ChannelInfo> channelInfoList = channelInfoMapper.fandPageChannelInfo(channelInfo);
        /*System.out.println(PageHelper.count(new ISelect() {
            @Override
            public void doSelect() {

            }Date
        }));*/
        //System.out.println(page.);

        PageInfo pageInfo = new PageInfo(channelInfoList);
        System.out.println(pageInfo.getTotal());
        System.out.println("testDate:"+pageInfo);

        //Page p = (Page)channelInfoList;
        //System.out.println(p);
        return channelInfoList;
    }
}
